package com.kotlin.demo.泛型

/**
 * Kotlin 类型限定
 */

open class MyAnyClass(name: String)

open class Person(name: String) : MyAnyClass(name = name)

class Teacher(name: String) : Person(name = name)

class Student(name: String) : Person(name = name)

class Dog(name: String)


/**
 * T : Person  等价于 Java的  T extends Person
 */
class KtBase106<T : Person>(private val obj: T, private val isObj: Boolean = true) {

    fun getObj2() = obj.takeIf { isObj }

}

fun main() {

    KtBase106(Person("person"))
    KtBase106(Teacher("person"))
    KtBase106(Student("person"))

//    KtBase106(Dog("person"))



}